import { getBarHeightInfo, setBarHeightInfo } from '@/utils/auth'

const state = {
  statusBarHeight: getBarHeightInfo()
}

const mutations = {
  CHANGE_BARHEIGHT: (state, data) => {
     state.statusBarHeight = data
  }
}

const actions = {
  changeBarHeight({ commit }, data) {
	uni.getSystemInfo({
		success: (res) => {
			let data = res.statusBarHeight;
			// #ifdef H5
			// data = 16;  // 给H5默认值
			data = 12;  // 给H5默认值
			// #endif
			// #ifdef  APP-PLUS
			data = Number(data) + 17;
			// #endif
			// #ifdef MP-WEIXIN
			// 获取微信胶囊的位置信息
			let obj = wx.getMenuButtonBoundingClientRect();
			data = (obj.height / 2) + res.statusBarHeight - 8;
			// console.log(data,res.statusBarHeight, '====获取微信胶囊的位置信息===');
			// #endif
			commit('CHANGE_BARHEIGHT', data)
			setBarHeightInfo(data);
		}
	});
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

